/**
 * Created by kayak-lic on 16/11/9.
 */
import React from 'react';
import util from 'util';
import {Switch, Input, Row, Col, Button, Table, Modal, Form, Collapse, Card, Radio, Tabs} from 'antd';
import {SearchDemo, RightButton, ColsEdit, Simeditor} from 'kpl';
import sys_dict from "sys_dict";

class ZnckResultSelect extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            tblSource: [],
            isLoading: false,
        };
        this.searchParams = {
            "page": 1,
            "rows": sys_dict.defaultPageSize.toString(),
        };
    }

    refresh(paramdic) {
        this.setState({isLoading: true});
        util.httpRequest({
            type: "POST", url: 'log040304.json', plattype: 'market/', params: paramdic, success: function (result) {
                this.setState({
                    tblSource: result.rows,
                    totalCount: result.total,
                    isLoading: false,
                });
            }.bind(this)
        });
    }

    search(params) {

        params.page = "1";
        params.start_date = util.date2str(params.start_date);
        params.end_date = util.date2str(params.end_date);
        params.rows = sys_dict.defaultPageSize.toString();
        this.refresh(params);
    }

    onShowSizeChange(current, pageSize) {
        let params = this.searchParams;
        params.rows = pageSize;
        params.page = current;
        this.refresh(params);
    }

    onChange(page) {
        let params = this.searchParams;
        params.page = page;
        this.refresh(params);
    }

    componentDidMount() {
        this.refresh(this.searchParams);
    }

    config() {
        const pagination = {
            total: this.state.totalCount,
            showSizeChanger: true,
            showQuickJumper: true,
            isLoading: false,
            pageSizeOptions: sys_dict.pageSizeOptions,
            defaultPageSize: sys_dict.defaultPageSize,
            onShowSizeChange: this.onShowSizeChange.bind(this),
            onChange: this.onChange.bind(this),
        };

        return {
            tableConfig: {
                pagination: pagination,
                dataSource: this.state.tblSource,
                columns: [
                    {
                        title: '客户名称',
                        dataIndex: 'user_name',
                        key: '--3',
                    }, {
                        title: '客户手机号',
                        dataIndex: 'mobile',
                        key: '--4',
                    },
                    {
                        title: '产品名称',
                        dataIndex: '--',
                        key: '--5',
                    },
                    {
                        title: '加息幅度',
                        dataIndex: 'add_interest',
                        key: 'add_interest',
                    },
                    {
                        title: '加息日期',
                        dataIndex: 'add_interest_date_time',
                        key: 'add_interest_date_time',
                    }, {
                        title: '操作状态',
                        dataIndex: 'add_interest_status',
                        key: 'add_interest_status',
                    }
                ]
            },
        }
    }

    render() {

        let config = this.config();
        const searchConfig = {
            searchTitle: "查询条件",
            searchInit: {
                voucher_name: "",
                status: "",
                min_market_price: "",
                max_market_price: "",
                min_real_price: "",
                max_real_price: ""
            },
            searchField: [
                [

                    {propsname: "使用时间", propsKey: "start_date", propsType: "datepicker", key: "112"},
                    {propsname: "至", propsKey: "end_date", propsType: "datepicker", key: "113"},
                ],
                [
                    {propsname: "客户姓名", propsKey: "user_name", propsType: "input", key: "115"},
                    {propsname: "加息状态", propsKey: "add_interest_status", propsType: "input", key: "115"}
                ], []
            ]
        };
        return (
            <div>
                <SearchDemo search={this.search.bind(this)} searchConfig={searchConfig}></SearchDemo>
                <Table {...config.tableConfig}></Table>
            </div>
        );
    }
}

export default ZnckResultSelect;